// 配置
import Vue from 'vue'
import VueRouter from "vue-router";
<<<<<<< HEAD

// 路由组件
import Home from "../pages/Home/index.vue";
import Logon from "../pages/Logon/index.vue";
import Search from "../pages/Search/index.vue";
import Register from "../pages/Register/index.vue";

const _Push = VueRouter.prototype.push;
const _Replace = VueRouter.prototype.replace;
function vr(p, _pr) {
=======
import store from "@/store/index.js";

// 路由组件
import Home from "../pages/Home/index.vue";
import Login from "../pages/Login/index.vue";
import Search from "../pages/Search/index.vue";
import Register from "../pages/Register/index.vue";
import Detail from "@/pages/Detail/index.vue";
import AddCartSuccess from "@/pages/AddCartSuccess/index.vue";
import ShopCart from "@/pages/ShopCart/index.vue";
import Trade from "@/pages/Trade/index.vue";

const _Push = VueRouter.prototype.push;
const _Replace = VueRouter.prototype.replace;
function vr(p, _pr) {  
>>>>>>> ecb56e7 (first commit)
  VueRouter.prototype[p] = function(datas, resolve, reject) {
    if(resolve && reject) {
      _pr.call(this, datas, resolve, reject);
    }else {   
      _pr.call(this, datas,(value)=>{}, (err)=>{});
    }
  }
}
vr("push", _Push);
vr("replace", _Replace);

// 使用
Vue.use(VueRouter);

<<<<<<< HEAD
export default new VueRouter({
=======
let router = new VueRouter({
>>>>>>> ecb56e7 (first commit)
  routes: [
    // Home 组件
    {
      path: "/Home",
      component: Home,
      meta: {show: true},
    },    
    // Search
<<<<<<< HEAD
    {
      path: "/Search/:keys?",
      component: Search,
      meta: {show: true},
      name: "search",
    },
    // Logon
    {
      path: "/Logon",
      component: Logon,
=======
    {      
      path: "/Search/:keyword?",
      component: Search,
      meta: {show: true},
      name: "search",
    }, 
    // Detail 商品详情
    {
      path: "/Detail/:good_id?",
      component: Detail,
      meta: {show: true},
      name: "detail",
    },
    // AddCartSuccess 商品详情
    {
      path: "/AddCartSuccess",
      component: AddCartSuccess,
      meta: {show: true},
      name: "addCartSuccess",
    },
    // ShopCart 购物车
    {
      path: "/ShopCart",
      component: ShopCart,
      meta: {show: true},
      name: "shopcart",
    },
    // Trade 结算
    {
      path: "/Trade",
      component: Trade,
      meta: {show: true},
      name: "trade",
    },



    // Login
    {
      path: "/Login",
      component: Login,
>>>>>>> ecb56e7 (first commit)
      meta: {show: false},
    },
    // Register
    {
      path: "/Register",
      component: Register,
      meta: {show: false},
    },
<<<<<<< HEAD
=======
   
>>>>>>> ecb56e7 (first commit)

    // 重定向 指定跳转页面
    {
      path: "*",
      redirect: "/Home",
    },
  ],
<<<<<<< HEAD
});

=======
  scrollBehavior (to, from, savedPosition) {
    return {y: 0}
  }
});

// 前置路由守卫
router.beforeEach(async (to, from, next) => {
  next()
  
  if(store.state.register.token) {
    if(to.path == "/Login") {
      next("/Home");
    }else {     
      try {
        await store.dispatch("getUserInfo");    
        next();
        
      }catch(err) {
        console.log(err);
      }
    }       
  }else {
    if(to.path != "/Login" && to.path != "/Register") {            
      next("/Home");
    }else {
      next();
    }
  }
})

export default router;
>>>>>>> ecb56e7 (first commit)
